home *** CD-ROM | disk | FTP | other *** search
/ Champak 86 / (Vol 86) My Disc.iso / Interface / it.dig / scripts / __Packages / mx / controls / gridclasses / DataGridRow.as < prev   
Encoding:
Text File  |  2009-06-09  |  7.4 KB  |  247 lines

  1. class mx.controls.gridclasses.DataGridRow extends mx.controls.listclasses.SelectableRow
  2. {
  3.    var colBG;
  4.    var cells;
  5.    var owner;
  6.    var backGround;
  7.    var text;
  8.    var textHeight;
  9.    var listOwner;
  10.    var columnIndex;
  11.    var __height;
  12.    var grandOwner;
  13.    var wasPressed;
  14.    var onPress;
  15.    function DataGridRow()
  16.    {
  17.       super();
  18.    }
  19.    function createChildren(Void)
  20.    {
  21.       this.setupBG();
  22.       this.colBG = this.createEmptyMovieClip("colbG_mc",mx.controls.listclasses.SelectableRow.LOWEST_DEPTH + 1);
  23.    }
  24.    function init(Void)
  25.    {
  26.       super.init();
  27.       this.cells = new Array();
  28.    }
  29.    function size(Void)
  30.    {
  31.       if(this.cells.length != this.owner.columns.length)
  32.       {
  33.          this.createCells();
  34.       }
  35.       super.size();
  36.    }
  37.    function createCells(Void)
  38.    {
  39.       this.clearCells();
  40.       this.backGround.onRelease = this.startEditCell;
  41.       var _loc7_ = this.owner.columns.length;
  42.       var _loc2_ = 0;
  43.       while(_loc2_ < _loc7_)
  44.       {
  45.          var _loc4_ = this.owner.columns[_loc2_];
  46.          var _loc5_ = _loc4_.__cellRenderer;
  47.          if(_loc5_ != undefined)
  48.          {
  49.             if(typeof _loc5_ == "string")
  50.             {
  51.                var _loc0_ = null;
  52.                var _loc3_ = this.cells[_loc2_] = this.createObject(_loc5_,"fCell" + _loc2_,2 + _loc2_,{styleName:_loc4_});
  53.             }
  54.             else
  55.             {
  56.                var _loc0_ = null;
  57.                _loc3_ = this.cells[_loc2_] = this.createClassObject(_loc5_,"fCell" + _loc2_,2 + _loc2_,{styleName:_loc4_});
  58.             }
  59.          }
  60.          else
  61.          {
  62.             var _loc0_ = null;
  63.             _loc3_ = this.cells[_loc2_] = this.createLabel("fCell" + _loc2_,2 + _loc2_);
  64.             _loc3_.styleName = _loc4_;
  65.             _loc3_.selectable = false;
  66.             _loc3_.backGround = false;
  67.             _loc3_.border = false;
  68.             _loc3_._visible = false;
  69.             _loc3_.getPreferredHeight = this.cellGetPreferredHeight;
  70.          }
  71.          _loc3_.listOwner = this.owner;
  72.          _loc3_.columnIndex = _loc2_;
  73.          _loc3_.owner = this;
  74.          _loc3_.getCellIndex = this.getCellIndex;
  75.          _loc3_.getDataLabel = this.getDataLabel;
  76.          _loc2_ = _loc2_ + 1;
  77.       }
  78.    }
  79.    function cellGetPreferredHeight()
  80.    {
  81.       var _loc3_ = this.text;
  82.       this.text = "^g_p";
  83.       this.draw();
  84.       var _loc2_ = this.textHeight + 4;
  85.       this.text = _loc3_;
  86.       return _loc2_;
  87.    }
  88.    function getCellIndex(Void)
  89.    {
  90.       return {columnIndex:this.columnIndex,itemIndex:this.owner.rowIndex + this.listOwner.__vPosition};
  91.    }
  92.    function getDataLabel()
  93.    {
  94.       return this.listOwner.columns[this.columnIndex].columnName;
  95.    }
  96.    function clearCells()
  97.    {
  98.       var _loc2_ = 0;
  99.       while(_loc2_ < this.cells.length)
  100.       {
  101.          this.cells[_loc2_].removeTextField();
  102.          this.cells[_loc2_].removeMovieClip();
  103.          _loc2_ = _loc2_ + 1;
  104.       }
  105.       this.cells.splice(0);
  106.    }
  107.    function setValue(itmObj, state, transition)
  108.    {
  109.       var _loc7_ = this.owner.columns;
  110.       var _loc8_ = _loc7_.length;
  111.       var _loc3_ = 0;
  112.       while(_loc3_ < _loc8_)
  113.       {
  114.          var _loc6_ = this.cells[_loc3_];
  115.          var _loc4_ = _loc7_[_loc3_];
  116.          var _loc2_ = _loc4_.__labelFunction(itmObj);
  117.          if(_loc2_ == undefined)
  118.          {
  119.             _loc2_ = !(itmObj instanceof XMLNode) ? itmObj[_loc4_.columnName] : itmObj.attributes[_loc4_.columnName];
  120.          }
  121.          if(_loc2_ == undefined)
  122.          {
  123.             _loc2_ = " ";
  124.          }
  125.          _loc6_.setValue(_loc2_,itmObj,state);
  126.          _loc3_ = _loc3_ + 1;
  127.       }
  128.    }
  129.    function drawCell(cellNum, xPos, w, bgCol)
  130.    {
  131.       var _loc2_ = this.cells[cellNum];
  132.       _loc2_._x = xPos;
  133.       _loc2_._visible = true;
  134.       _loc2_.setSize(w - 2,Math.min(this.__height,_loc2_.getPreferredHeight()));
  135.       _loc2_._y = (this.__height - _loc2_.height) / 2;
  136.       if(bgCol != undefined)
  137.       {
  138.          var _loc3_ = Math.floor(xPos - 2);
  139.          var _loc4_ = Math.floor(_loc3_ + w);
  140.          this.colBG.moveTo(_loc3_,0);
  141.          this.colBG.beginFill(bgCol);
  142.          this.colBG.lineStyle(0,0,0);
  143.          this.colBG.lineTo(_loc4_,0);
  144.          this.colBG.lineTo(_loc4_,this.__height);
  145.          this.colBG.lineTo(_loc3_,this.__height);
  146.          this.colBG.endFill();
  147.       }
  148.    }
  149.    function setState(newState, transition)
  150.    {
  151.       var _loc6_ = this.owner.columns;
  152.       var _loc4_ = _loc6_.length;
  153.       if(newState != "normal" || !this.owner.enabled)
  154.       {
  155.          var _loc5_ = undefined;
  156.          if(!this.owner.enabled)
  157.          {
  158.             _loc5_ = this.owner.getStyle("disabledColor");
  159.          }
  160.          else if(newState == "highlighted")
  161.          {
  162.             _loc5_ = this.owner.getStyle("textRollOverColor");
  163.          }
  164.          else if(newState == "selected")
  165.          {
  166.             _loc5_ = this.owner.getStyle("textSelectedColor");
  167.          }
  168.          var _loc3_ = 0;
  169.          while(_loc3_ < _loc4_)
  170.          {
  171.             this.cells[_loc3_].setColor(_loc5_);
  172.             this.cells[_loc3_].__enabled = this.owner.enabled;
  173.             _loc3_ = _loc3_ + 1;
  174.          }
  175.       }
  176.       else
  177.       {
  178.          _loc3_ = 0;
  179.          while(_loc3_ < _loc4_)
  180.          {
  181.             this.cells[_loc3_].setColor(_loc6_[_loc3_].getStyle("color"));
  182.             this.cells[_loc3_].__enabled = this.owner.enabled;
  183.             _loc3_ = _loc3_ + 1;
  184.          }
  185.       }
  186.       super.setState(newState,transition);
  187.    }
  188.    function startEditCell()
  189.    {
  190.       var _loc2_ = this.grandOwner;
  191.       _loc2_.dontEdit = true;
  192.       _loc2_.releaseFocus();
  193.       delete _loc2_.dontEdit;
  194.       if(_loc2_.enabled && _loc2_.editable && this.owner.item != undefined)
  195.       {
  196.          var _loc9_ = this.owner.cells.length;
  197.          var _loc3_ = 0;
  198.          while(_loc3_ < _loc9_)
  199.          {
  200.             var _loc5_ = _loc2_.columns[_loc3_];
  201.             if(_loc5_.editable)
  202.             {
  203.                var _loc4_ = this.owner._xmouse - this.owner.cells[_loc3_]._x;
  204.                if(_loc4_ >= 0 && _loc4_ < _loc5_.__width)
  205.                {
  206.                   var _loc6_ = this.owner.rowIndex + _loc2_.__vPosition;
  207.                   _loc2_.setFocusedCell({itemIndex:_loc6_,columnIndex:_loc3_},true);
  208.                   if(this.wasPressed != true)
  209.                   {
  210.                      this.onPress();
  211.                      _loc2_.onMouseUp();
  212.                   }
  213.                   delete this.wasPressed;
  214.                   clearInterval(_loc2_.dragScrolling);
  215.                   delete _loc2_.onMouseUp;
  216.                   return undefined;
  217.                }
  218.             }
  219.             _loc3_ = _loc3_ + 1;
  220.          }
  221.       }
  222.    }
  223.    function bGOnPress(Void)
  224.    {
  225.       this.wasPressed = true;
  226.       this.grandOwner.pressFocus();
  227.       this.grandOwner.onRowPress(this.owner.rowIndex);
  228.    }
  229.    function notifyStyleChangeInChildren(sheetName, styleProp, newValue)
  230.    {
  231.       var _loc6_ = this.owner.columns;
  232.       var _loc4_ = this.cells.length;
  233.       var _loc3_ = 0;
  234.       while(_loc3_ < _loc4_)
  235.       {
  236.          var _loc2_ = this.cells[_loc3_];
  237.          if(_loc2_.stylecache != undefined)
  238.          {
  239.             delete _loc2_.stylecache.tf;
  240.          }
  241.          delete _loc2_.enabledColor;
  242.          _loc2_.invalidateStyle(styleProp);
  243.          _loc3_ = _loc3_ + 1;
  244.       }
  245.    }
  246. }
  247.